#ifndef _KASISKI_H_
#define _KASISKI_H_

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../spanishFreq.h"
#include "dataProcessing.h"

#define MAX_KEY_LENGTH 10
#define SEQ_LENGTH 4
#define NUM_ITEMS 10
#define NUM_RESP 6

typedef struct strDist
{
	int dist;
	unsigned char seqLength;
} strDist;

typedef struct vigColum
{
	int * col;
	int size;
} vigColum;

/**
 * Finds the length of the key of the Vigenere encrypted text.
 *
 * @param[in]	s		    The encrypted text.
 * @param[in]	size	    The length of the encrypted text.
 *
 * @return	Key length, or lower than zero in case of error.
 */
int * findKeyLength (int * s, int size);
                        
/**
 * Computes the length of the key based on the distances between
 * repeated sequences in the text.
 *
 * @param[in]	distances	Array containing the distances between
 * 							repeated sequences in the text.
 *
 * @param[in]	numDist		The number of distances in the array.
 * 
 * @return	Key length, or lower than zero in case of error.
 */
int * calcKeyLength(strDist * distances, int numDist);

/**
 * Computes the greatest common divisor between two numbers.
 *
 * @param[in]	n1		    The first number.
 *
 * @param[in]	n2		    The second number.
 *
 * @return	Greatest common divisor between both numbers.
 */
int maxDivisor(int n1, int n2);

/**
 * Decrypts the vigenere encrypted text.
 *
 * @param[in]	s		    The encrypted text.
 * @param[in]	size	    The length of the encrypted text.
 *
 * @return	-.
 */
void solveVigenere(int * s, int size);

//alocacion y liberacion, despues las comento mejor
vigColum * allocColumns(int textSize, int keyLength);
void freeColumns(vigColum * columns, int length);

//cesar para columnas. ver si lo mejoro *-*. La i dice cesar elige:
//si el de mayor frecuencia, el 2do, etc
void colCesar(int* s, long size, alphabetArray cypherFreq, int i);

vigColum * makeColumns(int size, int * s, int keyLength);

#endif 
